package com.loy.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloCOntroller {

    @GetMapping("/hello")
    public String hello(){
        System.out.println("hello security");
        // 获取认证信息
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        User principal = (User) authentication.getPrincipal();
        System.out.println(principal.getUsername());// 获取当前登录用户的身份信息
        System.out.println(authentication.getAuthorities());// 获取当前登录用户的权限信息
        return "hello security";
    }

    @GetMapping("/index")
    public String index(){
        System.out.println("hello index");
        return "hello index";
    }
}
